//
//  MXViewController.m
//  MozaFFmpeg
//
//  Created by michaelxiaonull on 08/21/2020.
//  Copyright (c) 2020 michaelxiaonull. All rights reserved.
//

#import "MXViewController.h"
#import "MozaFFmpeg.h"

@interface MXViewController ()

@end

@implementation MXViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    //[self test];
    NSString *src = [[NSBundle mainBundle] pathForResource:@"idr" ofType:@"MP4"];
    NSString *dst = [NSString stringWithFormat:@"%@/%@", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject], @"idr4.jpg"];
    [MozaFFmpeg idrToJpgFromSrc:src dst:dst completion:^(UIImage *image, int ret) {
        NSLog(@"image: %@", image);
    }];
}

- (IBAction)test {
    //NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"mp4"];
    NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"idr" ofType:@"MP4"];
    NSString *imageName = @"idr3.jpg";
    NSString *imagesPath = [NSString stringWithFormat:@"%@/%@", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject], imageName];
    
    //        arguments[0] = "ffmpeg";
    //        arguments[1] = "-i";
    //        arguments[2] = (char *)[moviePath UTF8String];
    //        arguments[3] = "-r";
    //        arguments[4] = "20";
    //        arguments[5] = (char *)[imagesPath UTF8String];
    NSArray *args = @[@"-i",
                      [NSString stringWithFormat:@"%s", moviePath.UTF8String],
                      @"-r",
                      @"1",
                      @"-f",
                      @"image2",
                      [NSString stringWithFormat:@"%s", imagesPath.UTF8String]];
    [MozaFFmpeg runCmdWithArgs:args completion:^(int ret) {
        //NSLog(@"image: %@", image);
    }];
}

@end
